Fix inference for properties with __call__#15926
Conversation
This comment has been minimized.
This comment has been minimized.
4eb58d6 to
68bcd7a
Compare
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ilevkivskyi
left a comment
There was a problem hiding this comment.
LG, but I have some suggestions
| result = expanded_signature.ret_type | ||
| else: | ||
| result = expanded_signature | ||
| if var.is_initialized_in_class and (not is_instance_var(var) or mx.is_operator): |
There was a problem hiding this comment.
Would it be possible to avoid extra nesting level by computing something before the first if? If yes, I would prefer that. This function is already hard to read.
| class A: | ||
| @property | ||
| @decorator | ||
| def f(self) -> int: ... |
There was a problem hiding this comment.
People recently complained (don't remember where) that this use case:
def make_method() -> SomeCallbackProtocol: ...
class A:
meth = make_method()is not handled the same way as
def make_method_callable() -> Callable[[int], int]: ...
class B:
meth = make_method_callable()(because certain special-casing only applies to callable types). I am 95% sure this PR should fix that as well (or maybe with very few modifications), if yes, could you please add such test as well?
There was a problem hiding this comment.
Thanks for mentioning this! It's not fixed by this change, but should be doable fix. I will make a follow up PR
|
Diff from mypy_primer, showing the effect of this PR on open source code: twine (https://github.com/pypa/twine)
+ twine/settings.py:131: error: Redundant cast to "str | None" [redundant-cast]
+ twine/settings.py:137: error: Redundant cast to "str | None" [redundant-cast]
|
Fixes #5858